<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/7/1
  Time: 9:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>$</title>
    <link rel="stylesheet" href="css/css.css">
    <link rel="stylesheet" href="css/img.css">
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/fileupload.js"></script>
    <script src="js/validate.js"></script>
    <script src="js/jquery.validate.js"></script>
    <script>
        $(function () {
            $.ajax({
                url: "city.do",
                type: "post",
                data:{"pid":0},
                dataType: "json",
                success:function (obj) {
                    for (let x in obj) {
                        $("[name='sheng']").append('<option value="'+obj[x].id+'">'+obj[x].name+'</option>')
                    }
                }
            })
            $("[name='sheng']").change(function () {
                var pid=$(this).val()
                $("[name='shi']").empty()
                $("[name='shi']").append('<option value="">请选择</option>')
                $("[name='xian']").empty()
                $("[name='xian']").append('<option value="">请选择</option>')
                $.ajax({
                    url: "city.do",
                    type: "post",
                    data:{"pid":pid},
                    dataType: "json",
                    success:function (obj) {
                        for (let x in obj) {
                            $("[name='shi']").append('<option value="'+obj[x].id+'">'+obj[x].name+'</option>')
                        }
                    }
                })
            })
            $("[name='shi']").change(function () {
                var pid=$(this).val()
                $("[name='xian']").empty()
                $("[name='xian']").append('<option value="">请选择</option>')
                $.ajax({
                    url: "city.do",
                    type: "post",
                    data:{"pid":pid},
                    dataType: "json",
                    success:function (obj) {
                        for (let x in obj) {
                            $("[name='xian']").append('<option value="'+obj[x].id+'">'+obj[x].name+'</option>')
                        }
                    }
                })
            })
        })
        function fenye(pages) {
            $("[name='pages']").val(pages);
            $("form").submit();
        }
        function delAll() {
            var str="";
            $("[name='sid']:checked").each(function () {
                str+=","+$(this).val();
            })
            var sid=str.substring(1);
            $.ajax({
                url: "dels.do",
                type: "post",
                data:{"sid":sid},
                dataType: "json",
                success:function (obj) {
                    alert("删除成功")
                    location.href="list.do";
                }
            })
        }
        function del(sid) {
            $.ajax({
                url: "del.do",
                type: "post",
                data:{"sid":sid},
                dataType: "json",
                success:function (obj) {
                    alert("删除成功")
                    location.href="list.do";
                }
            })
        }
        function fx() {
           $("[name='sid']").each(function () {
               $(this).prop("checked",!$(this).prop("checked"));
           })




        }
    </script>
</head>
<body>
欢迎【 ${user.nick} 】登录
<hr>
<form action="list.do" method="post">
    <input type="hidden" name="pages">
    名字:<input type="text" name="sname" value="${map.sname}">
    生日:<input type="date" name="start" value="${map.start}">~
    <input type="date" name="end" value="${map.end}">
    省:<select name="sheng">
    <option value="">请选择</option>
</select>
    市：<select name="shi">
    <option value="">请选择</option>
</select>
    县：<select name="xian">
    <option value="">请选择</option>
</select>
    <input type="submit">
</form>
<table border="10">
    <tr>
        <td>
            <input onclick="delAll()" type="button" value="批删">
            <input type="button" value="反选" onclick="fx()">
        </td>
        <td>编号</td>
        <td>名字</td>
        <td>性别</td>
        <td>年龄</td>
        <td>电话</td>
        <td>生日</td>
        <td>爱好</td>
        <td>头像</td>
        <td>省</td>
        <td>市</td>
        <td>县</td>
        <td>登录用户</td>
        <td>课程</td>
        <td>
            <a href="toadd.do">

                <input type="button" value="添加"></a>
        </td>
    </tr>
    <c:forEach items="${pageInfo.list}" var="s">
        <tr>
            <td>
                <input type="checkbox" value="${s.sid}" name="sid">
            </td>
            <td>${s.sid}</td>
            <td>${s.sname}</td>
            <td>${s.sex==1?'男':'女'}</td>
            <td>${s.age}</td>
            <td>${s.tel}</td>
            <td>${s.birth}</td>
            <td>${s.hobby}</td>
            <td>
                <img src="${s.pic1}" alt="无法展示" width="30px">
                <img src="${s.pic2}" alt="无法展示" width="30px">
                <img src="${s.pic3}" alt="无法展示" width="30px">
                <img src="${s.pic4}" alt="无法展示" width="30px">
                <img src="${s.pic5}" alt="无法展示" width="30px">
            </td>
            <td>${s.aname}</td>
            <td>${s.bname}</td>
            <td>${s.cname}</td>
            <td>${s.uname}</td>
            <td>${s.tnames}</td>
            <td>
                <input type="button" value="删除" onclick="del(${s.sid})">
                <a href="toupd.do?sid=${param.sid}"><input type="button" value="修改"></a>
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="20">
            <input type="button" class="btn btn-info" value="首页" onclick="fenye(1)">
            <input type="button" class="btn btn-info" value="上一页" onclick="fenye(${pageInfo.isFirstPage?1:pageInfo.prePage})">
            <input type="button" class="btn btn-info" value="下一页" onclick="fenye(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">
            <input type="button" class="btn btn-info" value="尾页" onclick="fenye(${pageInfo.pages})">
        </td>
    </tr>
</table>
</body>
</html>
